﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms;

namespace MacomberMapSystem.Common.User_Interfaces.Editors
{
    /// <summary>
    /// This class offers a folder browser
    /// </summary>
    public class MM_File_Browser: UITypeEditor
    {
   
        /// <summary>
        /// Allow the locating of our file
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            String CurValue = Convert.ToString(value);
            using (OpenFileDialog oFd = new OpenFileDialog())
            {
                oFd.FileName = CurValue;
                if (oFd.ShowDialog() == DialogResult.OK)
                    return oFd.FileName;
                else
                    return CurValue;
            }
        }

        /// <summary>
        /// Report the editing style for our control
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

    }
}
